/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilities;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author asmaa
 */
public class CustomFileChooser extends JFileChooser {

    public CustomFileChooser() {
        super();
    }

    @Override
    public void approveSelection() {
        File f = getSelectedFile();
        if (f.exists() && getDialogType() == SAVE_DIALOG) {
            int result = JOptionPane.showConfirmDialog(this, "The file exists, overwrite?", "Existing file", JOptionPane.OK_CANCEL_OPTION);
            switch (result) {
                case JOptionPane.OK_OPTION:
                    super.approveSelection();
                    return;
                case JOptionPane.CANCEL_OPTION:
                    return;
            }
        }
        super.approveSelection();
    }
}
